package pikes.html.xhtml.list;

import java.util.LinkedList;

import pikes.html.xhtml.Block;
import pikes.html.xhtml.CoreAttributes;
import pikes.html.xhtml.Events;
import pikes.html.xhtml.Flow;
import pikes.html.xhtml.I18N;
import pikes.html.xhtml.NonRootTagFactory;
import pikes.xml.XMLTag;
import pikes.util.Assert;

/**
 * Common abstract class for <code>&lt;ol/&gt;</code> and <code>&lt;ul/&gt;</code> tags, see <a
 * href="http://www.w3.org/TR/html401/struct/lists.html#h-10.2">lists element</a> in HTML specification.
 * @author Peter Bona
 * @see <a href="http://www.w3.org/TR/html401/struct/lists.html#h-10.2">The list elements in HTML specification</a>
 */
public abstract class List extends NonRootTagFactory implements Block, CoreAttributes, I18N, Events {

	private java.util.List<ListItem> items = new LinkedList<ListItem>();

	protected List(ListItem item) {
		Assert.notNull(item);
		items.add(item);
	}

	protected List(CharSequence text) {
		Assert.notNull(text);
		items.add(new ListItem(text));
	}

	protected List(Flow flow) {
		Assert.notNull(flow);
		items.add(new ListItem(flow));
	}

	public void add(CharSequence text) {
		if (text != null) {
			items.add(new ListItem(text));
		}
	}

	public void add(Flow flow) {
		if (flow != null) {
			items.add(new ListItem(flow));
		}
	}

	public void add(ListItem item) {
		if (item != null) {
			items.add(item);
		}
	}

	@Override
	protected void decorateCreatedTag(XMLTag tag) {
		for (ListItem item : items) {
			item.decorateTag(tag);
		}
	}

}
